﻿using AutoMapper;
using B.S.Data.MES.API.Applications.BaseData.Command.ChanXIanCommand;
using B.S.Domain.BasicData.Factory_modeling.Production_line_management;
using B.S.Domain.BasicData.Factory_modeling.shop_management;
using B.S.Infratrctrue;
using B.S.Requst;
using MediatR;
using Microsoft.EntityFrameworkCore.Infrastructure;

namespace B.S.Data.MES.API.Applications.BaseData.CommandHandlers.ChanXIanCommandHandlers
{
    public class AddChanXIanCommandHandlers : IRequestHandler<AddChanXianCommand, APIRequst<int>>
    {
        private readonly Infratrctrue.IBaseRepository<Production_line_management> proRepository;
        private readonly IMapper mapper;

        public AddChanXIanCommandHandlers(IBaseRepository<Production_line_management> ProRepository,IMapper mapper )
        {
            proRepository = ProRepository;
            this.mapper = mapper;
        }

        public async Task<APIRequst<int>> Handle(AddChanXianCommand request, CancellationToken cancellationToken)
        {
            Production_line_management shop = mapper.Map<Production_line_management>(request);
            shop.CreateTime = DateTime.Now;
            await proRepository.Add(shop);
            return new APIRequst<int>
            {
                Msg=RequstCode.成功.ToString(),
                Code=RequstCode.成功,
            };
        }
    }
}
